"use strict";
cc._RF.push(module, 'e92a2mgr9REbpBlPqWKDN8c', 'SelectLevel');
// script/SelectLevel.js

"use strict";

/**
 *选关界面
*/
cc.Class({
    extends: cc.Component,

    properties: {
        levelSmall: cc.Prefab,
        levelBig: cc.Prefab

    },

    onLoad: function onLoad() {
        this.index = 0;
        this.bgColor = [cc.Color.CYAN, cc.Color.YELLOW, cc.Color.MAGENTA];
        this.stageNode = this.node.getChildByName("stage_node");
        this.init();
    },
    start: function start() {

        for (var i = 0; i < 3; i += 1) {
            this.stageNode.children[i].active = true;
        }
    },
    init: function init() {
        var _this = this;

        var ran = Math.random() * 3 | 0;

        var _loop = function _loop(i) {
            var level_S = cc.instantiate(_this.levelSmall);
            level_S.x = -220 + i % 3 * 220;
            level_S.color = _this.bgColor[ran];
            cc.loader.loadRes("label/label_" + parseInt(i + 1), cc.SpriteFrame, function (err, frame) {
                if (err) {
                    cc.log(err);
                }
                level_S.getChildByName("label").getComponent(cc.Sprite).spriteFrame = frame;
            });
            _this.stageNode.addChild(level_S);
        };

        for (var i = 0; i < 12; i += 1) {
            _loop(i);
        }
        this.btnColor(this.bgColor[ran]);
    },
    btnColor: function btnColor(c) {
        this.node.getChildByName('cup_btn').color = c;
        this.node.getChildByName('setting_btn').color = c;
        this.node.getChildByName('ranking_btn').color = c;
        this.node.getChildByName('back_btn').color = c;
        this.node.getChildByName('star_btn').color = c;
    },
    changePage: function changePage(event, customData) {
        for (var j = 0; j < 3; j += 1) {
            this.stageNode.children[this.index + j].active = false;
            this.stageNode.children[this.index + 3 * customData + j].active = true;
        }
        this.index = this.index + 3 * customData;
        if (this.index === 0) {
            this.node.getChildByName('prePage_btn').active = false;
        } else {
            this.node.getChildByName('prePage_btn').active = true;
        }
        if (this.index === 9) {
            this.node.getChildByName('nextPage_btn').active = false;
        } else {
            this.node.getChildByName('nextPage_btn').active = true;
        }
        var ran = Math.random() * 3 | 0;
        for (var i = 0; i < 12; i += 1) {
            this.stageNode.children[i].color = this.bgColor[ran];
        }
        this.btnColor(this.bgColor[ran]);
    }
}

// update (dt) {},
);

cc._RF.pop();